;##################################
;命令：
;nasm -f elf64 day11_goslp_pro.asm -o main.o && gcc main.o -o main -lc -no-pie && ./main
;输出：
;Value in arr[0] is 1.234500.
;Value in arr[1] is 2.345600.
;Value in arr[2] is 3.456700.
;Value in arr[3] is 4.567800.
;##################################
extern printf

section .data
	msg: db `Value in arr[%d] is %f.\n`, 0
	arr: dd 0, 1.1111, 2.2222, 3.3333, 4.4444, 15.5554, 16.6665, 26.6664

section .text
	global main

main:
	push rbp
	mov rbp, rsp

;####################################################################################
	;除法
	;float A1 = L5 / L2;
	;float A2 = L6 / L3;
	;float A3 = L7 / L4;
	;7 = 15.5554 / 2.2222
	;5 = 16.6665 / 3.3333
	;6 = 26.6664 / 4.4444
	vmovups xmm0, [arr + 4 * 5]
	vdivps xmm0, [arr + 4 * 2]

	;shuffle
	vshufps xmm0, xmm0, xmm0, 00001001b

	;float A4 = L1 - A2;
	;float A5 = L2 - A3;
	;float A6 = L3 - A1;
	;-3.8889 = 1.1111 - 5
	;-3.7778 = 2.2222 - 6
	;-3.6667 = 3.3333 - 7
	;减法
	vmovups xmm1, [arr + 4 * 1]
	vsubps xmm0, xmm1, xmm0
	
	;存放
	;先存放前两个，再存放最后一个
	;arr[0] = -3.8889;
	;arr[1] = -3.7778;
	;arr[2] = -3.6667;
	vmovlps [arr], xmm0
	vextractps [arr + 4 * 2], xmm0, 2
;####################################################################################

;######################################################
	;打印
	mov ebx, 0
	jmp compare

execute:
	mov rdi, msg
	movsxd rsi, ebx
	cvtss2sd xmm0, dword [arr + 4 * ebx]
	movq rdx, xmm0
	call printf

	inc ebx

compare:
	cmp ebx, 8
	jl execute
;######################################################

	mov eax, 0
	leave
	ret
